import 'package:flutter/material.dart';
import 'package:healthy_station_flutter/utils/res_images.dart';
import 'package:provider/provider.dart';

import '../../network/XHttp.dart';
import '../../network/api.dart';
import '../../provider/provider_login.dart';
import '../../utils/constants.dart';
import '../../utils/log_utils.dart';
import '../../utils/res_colors.dart';
import '../../utils/screen_adapter.dart';

/// 
/// @Description 
/// @Author WuJianFeng
/// @Date 2024/3/14 13:37
/// 

class LoginSuccessWidget extends StatefulWidget{
  const LoginSuccessWidget({super.key});

  @override
  State<StatefulWidget> createState() => _LoginSuccessWidgetState();
  
}

class _LoginSuccessWidgetState extends State<LoginSuccessWidget>{
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: Adapt.pt(80)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          ///个人信息
          Row(
            mainAxisAlignment:MainAxisAlignment.center,
            children: [
              ImageUtils.getImgWithSize("avater_man.webp", 180, 240),
              Container(
                margin: EdgeInsets.only(left: Adapt.pt(50)),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    userInfoWidget("姓名：",Constant.userName),
                    userInfoWidget("性别：",Constant.userGender,marginTop: 46),
                    userInfoWidget("年龄：",Constant.age,marginTop: 46),
                  ],
                ),
              )
            ],
          ),

          Consumer<LoginProvider>(builder: (context, LoginProvider loginProvider, child) {
            return InkWell(
              onTap: (){
                logout((){
                  loginProvider.setLoginType(loginTypeInit);

                });
              },
              child: Container(
                width: Adapt.pt(342),
                height: Adapt.pt(91),
                margin: EdgeInsets.only(top: Adapt.pt(64)),
                alignment: Alignment.center,
                decoration:  BoxDecoration(
                  gradient:  const LinearGradient(
                    begin: FractionalOffset.topCenter,
                    end: FractionalOffset.bottomCenter,
                    colors: [
                      color_97c3fe,
                      color_3a7afe,
                    ],
                  ),
                  borderRadius:  BorderRadius.circular(Adapt.pt(15)),
                ),
                child: Text("退出登录",style: TextStyle(fontSize: Adapt.pt(42),color: Colors.white)),
              ),
            );

          }),
        ],
      ),
    );
  }

  Widget userInfoWidget(String preContent, String content, {marginTop = 0}){
    return Container(
      margin: EdgeInsets.only(top: Adapt.pt(marginTop)),
      child: RichText(
        text: TextSpan(
            text: preContent,
            style: TextStyle(fontSize: Adapt.pt(28), color: color_25364B),
            children: [
              TextSpan(
                  text: content,
                  style: TextStyle(
                      fontWeight:FontWeight.bold,
                      fontSize: Adapt.pt(28),
                      color: color_25364B))
            ]
        ),
      ),
    );

  }

  void logout(Function() logoutResult){

    XHttp.getInstance().post<String>(Api.logout).then((value){
      logoutResult();
      LogUtils.d("__developResident-value  code:${value.code}  message:${value.message}  data:${value.data}");
    }).catchError((err) {
      // DO SOMETHING
      LogUtils.d("__developResident-err $err");
    });

  }
  
}
 
 